home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume4 / echo < prev    next >
Encoding:
Text File  |  1989-02-03  |  4.8 KB  |  219 lines

  1. Path: xanth!mcnc!rutgers!ukma!cwjcc!hal!ncoast!allbery
  2. From: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
  3. Newsgroups: comp.sources.misc
  4. Subject: v04i088: Merged SysV/BSD echo
  5. Message-ID: <8809200631.AA19899@rocky2>
  6. Date: 25 Sep 88 01:23:44 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
  9. Lines: 207
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 4, Issue 88
  13. Submitted-by: "David MacKenzie" <edf@ROCKY2.ROCKEFELLER.EDU>
  14. Archive-name: echo
  15.  
  16. (An *echo program*???)  [My sentiments exactly.  ++bsa]
  17.  
  18. After seeing the (system-)vecho command included in the latest "less"
  19. distribution to address the problem of BSD/AT&T echo incompatibilities,
  20. I decided that someone might find this useful.  As far as I know, it's a
  21. complete implementation of both the System V and Berkeley echo's.  It
  22. should be especially useful for (non-SunOs) Berkeley users whose echo's
  23. are the dumber one and aren't built into the shells.  It's not derived
  24. from AT&T code . . . .
  25.  
  26. #! /bin/sh
  27. # This is a shell archive.  Remove anything before this line, then unpack
  28. # it by saving it into a file and typing "sh file".  To overwrite existing
  29. # files, type "sh file -c".  You can also feed this as standard input via
  30. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  31. # will see the following message at the end:
  32. #        "End of shell archive."
  33. # Contents:  echo.1 echo.c
  34. # Wrapped by dave@edfdc  on Tue Sep 20 02:27:38 1988
  35. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  36. if test -f 'echo.1' -a "${1}" != "-c" ; then 
  37.   echo shar: Will not clobber existing file \"'echo.1'\"
  38. else
  39. echo shar: Extracting \"'echo.1'\" \(832 characters\)
  40. sed "s/^X//" >'echo.1' <<'END_OF_FILE'
  41. X.TH ECHO 1
  42. X.SH NAME
  43. Xecho \- echo arguments
  44. X.SH SYNOPSIS
  45. X.B echo
  46. X[
  47. X.B \-n
  48. X] [
  49. X.B string...
  50. X]
  51. X.SH DESCRIPTION
  52. X.PP
  53. X.I Echo
  54. Xdisplays its arguments, separated by single spaces and followed by a
  55. Xnewline, on the standard output.  If no
  56. X.I string
  57. Xarguments are given,
  58. X.I echo
  59. Xproduces only the newline character.
  60. XIf the first argument is
  61. X.IR \-n ,
  62. Xthe trailing newline is omitted.  The
  63. X.I \-n
  64. Xis not echoed.
  65. X.PP
  66. X.I Echo
  67. Xrecognizes the following backslash escapes in the
  68. X.I string
  69. Xarguments:
  70. X.TP
  71. X\e0ooo
  72. Xoctal ASCII character (ooo are 1-3 octal digits)
  73. X.TP
  74. X\eb
  75. Xbackspace
  76. X.TP
  77. X\ec    
  78. Xomit trailing newline; don't print anything more (same as
  79. X.IR \-n )
  80. X.TP
  81. X\ef
  82. Xform feed
  83. X.TP
  84. X\en
  85. Xnewline (line feed)
  86. X.TP
  87. X\er
  88. Xcarriage return
  89. X.TP
  90. X\et
  91. Xhorizontal tab
  92. X.TP
  93. X\ev
  94. Xvertical tab
  95. X.TP
  96. X\e\e
  97. Xbackslash
  98. X.SH "SEE ALSO"
  99. Xcat(1v)
  100. X.SH AUTHOR
  101. XDavid MacKenzie (big deal)
  102. END_OF_FILE
  103. if test 832 -ne `wc -c <'echo.1'`; then
  104.     echo shar: \"'echo.1'\" unpacked with wrong size!
  105. fi
  106. # end of 'echo.1'
  107. fi
  108. if test -f 'echo.c' -a "${1}" != "-c" ; then 
  109.   echo shar: Will not clobber existing file \"'echo.c'\"
  110. else
  111. echo shar: Extracting \"'echo.c'\" \(1741 characters\)
  112. sed "s/^X//" >'echo.c' <<'END_OF_FILE'
  113. X/* xc
  114. X% cc -O echo.c -o echo
  115. X% strip echo
  116. X */
  117. X/*
  118. X * echo - echo arguments
  119. X * Usage: echo [-n] [string...]
  120. X *
  121. X * If the first argument is "-n", the trailing newline is omitted.
  122. X * The "-n" is not echoed.
  123. X *
  124. X * Recognizes System V escape sequences:
  125. X * \0ooo    octal ASCII character (1-3 digits)
  126. X * \b        backspace
  127. X * \c        omit trailing newline; don't print anything more (same as -n)
  128. X * \f        form feed
  129. X * \n        newline (line feed)
  130. X * \r        carriage return
  131. X * \t        horizontal tab
  132. X * \v        vertical tab
  133. X * \\        backslash
  134. X *
  135. X * David MacKenzie
  136. X * Latest revision: 08/07/88
  137. X */
  138. X
  139. X#include <stdio.h>
  140. X
  141. Xmain(argc, argv)
  142. X    int             argc;
  143. X    char          **argv;
  144. X{
  145. X    void            echo();
  146. X    register int    optind;
  147. X
  148. X    for (optind = 1; optind < argc; ++optind)
  149. X    if (optind != 1 || strcmp(argv[optind], "-n")) {
  150. X        echo(argv[optind]);
  151. X        if (optind < argc - 1)
  152. X        putchar(' ');
  153. X    }
  154. X    if (argc == 1 || strcmp(argv[1], "-n"))
  155. X    putchar('\n');
  156. X
  157. X    exit(0);
  158. X}
  159. X
  160. Xvoid
  161. Xecho(s)
  162. X    register char  *s;
  163. X{
  164. X    register int    i,        /* Digit counter for octal numbers. */
  165. X                    n;        /* Value of octal numbers. */
  166. X
  167. X    for (; *s; ++s) {
  168. X    if (*s != '\\')
  169. X        putchar(*s);
  170. X    else
  171. X        switch (*++s) {
  172. X        case 0:
  173. X        putchar('\\');
  174. X        return;
  175. X        case '\\':
  176. X        putchar('\\');
  177. X        break;
  178. X        case '0':
  179. X        for (i = n = 0, ++s; i < 3 && *s >= '0' && *s <= '7'; ++i, ++s)
  180. X            n += *s - '0';
  181. X        --s;
  182. X        putchar(n);
  183. X        break;
  184. X        case 'b':
  185. X        putchar(8);
  186. X        break;
  187. X        case 'c':
  188. X        exit(0);
  189. X        case 'f':
  190. X        putchar(12);
  191. X        break;
  192. X        case 'n':
  193. X        putchar('\n');
  194. X        break;
  195. X        case 'r':
  196. X        putchar('\r');
  197. X        break;
  198. X        case 't':
  199. X        putchar('\t');
  200. X        break;
  201. X        case 'v':
  202. X        putchar(11);
  203. X        break;
  204. X        default:
  205. X        putchar('\\');
  206. X        putchar(*s);
  207. X        break;
  208. X        }
  209. X    }
  210. X}
  211. END_OF_FILE
  212. if test 1741 -ne `wc -c <'echo.c'`; then
  213.     echo shar: \"'echo.c'\" unpacked with wrong size!
  214. fi
  215. # end of 'echo.c'
  216. fi
  217. echo shar: End of shell archive.
  218. exit 0
  219.